
//引入网络库
import { get, post } from "../../util/util.js"
// 获取全局应用程序实例对象
var app = getApp();

// 创建页面实例对象
Page({
  /**
   * 页面名称
   */
  name: "money",
  /**
   * 页面的初始数据
   */

  data: {
    payments: [],
    uid: '',
    // status: true,
    realAuth: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
  },
  onLoad: function (o) {//user/ModifyUserinfo
    var that = this;
    var sexStr = '';
    that.setData({
      uid: o.uid
    })
    wx.getStorage({
      key: 'login',
      success: function (res) {
        var data = res.data
        console.log("realAuth====" + data.data.realAuth);
        that.setData({
          uid: data.data.uid,
          realAuth: data.data.realAuth,
        });
      },
    })
    post("/user/mywallet", { uid: that.data.uid }).then(data => {
      that.setData({
        balance: data.data.balance,
        nickname: data.data.nickname,
      })
    })
    post("/user/getPayments", { uid: that.data.uid, pagesize: 1000 }).then(data => {
      that.setData({
        payments: data.data,
      })
    })

  },
  /**applyMoney
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var that = this;
    post("/user/mywallet", { uid: that.data.uid }).then(data => {
      that.setData({
        balance: data.data.balance,
        nickname: data.data.nickname,
      })
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  //以下为自定义点击事件
  applyMoney: function (e) {
    var that = this;
    post("/user/getApplyStatus", { uid: that.data.uid }).then(data => {
      if (data.code == 0) {
        if (data.data.status) {
          wx.showModal({
            title: '提示',
            content: "提现金额正在处理中,请稍后再试",
            success: function (res) {
              if (res.confirm) {
                console.log('用户点击确定')
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        } else {
          wx.navigateTo({
            url: '../sendMoney/sendMoney?uid=' + that.data.uid + '&realAuth=' + String(that.data.realAuth),
          })
        }
      }
    })
  }

})

